package com.zhangjk.sign.controller;

import com.zhangjk.sign.test.SignClient;
import com.zhangjk.sign.util.HttpClientUtils;


import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/sign/client")
public class SignClientController {

    /**
     * 模拟客户端请求API接口
     * @param request
     * @return
     */
    @GetMapping("send")
    public String send(HttpServletRequest request){
        Map<String,String> param = new HashMap<>();
        param.put("userId","9527");
        param.put("amount","9.99");
        param.put("productId","9885544154");
        param.put("secretKey","mysecret123456");
        try {
            Object jsonObject = HttpClientUtils.post("http://localhost:7006/sign/server/checkSign", SignClient.sign(param));
            return jsonObject.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "success";
    }


}
